package org.dormi.learn.product.domain.material.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

import java.util.Arrays;

/**
 * 产品跟踪/溯源
 *
 * @author : dormi330
 * @version : 1.0
 */
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum TrackingTypeEnum {

    UNIQUE_NUMBER("UNIQUE_NUMBER", "唯一编号"),
    LOTS_NUMBER("LOTS_NUMBER", "批次号"),
    NO_TRACKING("NO_TRACKING", "不跟踪"),
    ;

    TrackingTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @JsonCreator
    public static TrackingTypeEnum findValue(@JsonProperty("code") String code) {
        if (null == code) return null;

        return Arrays.stream(TrackingTypeEnum.values())
                .filter(pt -> pt.code.equals(code.toUpperCase()))
                .findFirst()
                .orElse(null);
    }

    private final String code;
    private final String name;

}
